/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

import java.io.UnsupportedEncodingException;
import java.util.Properties;
import javax.mail.Message;
import javax.mail.MessagingException;
import javax.mail.Session;
import javax.mail.Transport;
import javax.mail.internet.AddressException;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
/**
 *
 * @author 松鼠M
 */
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration({
    "file:web/WEB-INF/dispatcher-servlet.xml",
    "file:web/WEB-INF/applicationContext.xml"
})
public class testMail {


    @Test
    public void testMail() throws UnsupportedEncodingException {
        Properties props = new Properties();
        Session session = Session.getDefaultInstance(props, null);

        String msgBody = "Just test!";

        try {
            Message msg = new MimeMessage(session);
            msg.setFrom(new InternetAddress("myjkccd@gmail.com", "Example.com Admin"));
            msg.addRecipient(Message.RecipientType.TO,
                             new InternetAddress("myjkccd@gmail.com", "Mr. User"));
            msg.setSubject("Test GAE Mail");
            msg.setText(msgBody);
            Transport.send(msg);

        } catch (AddressException e) {
            // ...
        } catch (MessagingException e) {
            // ...
        }
    }
}
